Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-416

Null-valued pragma throws NPE in 3.3

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.3
    • 3.4.0
    • None
    • JEXL 3.3
      Java 21 (21+35) Red Hat, Inc.
      Linux 5.15.133.1-microsoft-standard-WSL2 (amd64)

    Description

      Version 3.2.1 seemed to allow null as a value for pragmas, but version 3.3 throws NPE.  I'm not necessarily advocating for null pragma values, but it's a behavior regression due to the use of TreeMap::merge. Even if disallowing nulls was desired, it should be a JexlException not NPE.

      Passes on 3.2.1:

      var script = engine.createScript("#pragma myNull null\n");
      var pragmas = script.getPragmas();
      assertTrue(pragmas.containsKey("myNull"), "pragma key present?");
      assertNull(pragmas.get("myNull"), "expected null value"); 

      Behavior on 3.3:

      assertThrows(
          NullPointerException.class,
          () -> engine.createScript("#pragma myNull null\n"));
      
      java.lang.NullPointerException
      	at java.base/java.util.Objects.requireNonNull(Objects.java:233)
      	at java.base/java.util.TreeMap.merge(TreeMap.java:743)
      	at org.apache.commons.jexl3.parser.JexlParser.declarePragma(JexlParser.java:557)
      	at org.apache.commons.jexl3.parser.Parser.Pragma(Parser.java:1246)
      	at org.apache.commons.jexl3.parser.Parser.JexlScript(Parser.java:63)
      	at org.apache.commons.jexl3.parser.Parser.parse(Parser.java:25)
      	at org.apache.commons.jexl3.internal.Engine.parse(Engine.java:1009)
      	at org.apache.commons.jexl3.internal.Engine.createScript(Engine.java:617)
      	at org.apache.commons.jexl3.internal.Engine.createScript(Engine.java:69)
      	at org.apache.commons.jexl3.JexlEngine.createScript(JexlEngine.java:375)
      

      Attachments

        Activity

          People

            henrib Henri Biestro
            wrprice William Price
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: